package com.linzelin.advice;


import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
//这里注意导入的AccessDeniedException是Spring的,不是java原生的那个夜异常

/**
 * 异常拦截器
 */
@ControllerAdvice
public class HandlerControllerException {

    /**
     * 还是熟悉的配置类,这里配置的就是对应会出现的异常了
     */
    @ExceptionHandler(RuntimeException.class)
    public String handException(RuntimeException e) {
        if (e instanceof AccessDeniedException) {
            return "redirect:/error/403";
        }
        return "redirect:/error";
    }
}
